import {
  Resolver,
  Query,
  Mutation,
  Args,
  Int,
  ResolveField,
  Parent,
} from '@nestjs/graphql';
import { RoleModelDataService } from './role-model-data.service';
import { RoleModelData } from './entities/role-model-datum.entity';
import { KeyValueList } from 'src/common/mongodb/commonSchema';
// import { UseGuards } from '@nestjs/common';
// import { JwtAuthGuard } from 'src/system/auth/guard/jwt-auth.guard';

@Resolver(() => RoleModelData)
export class RoleModelDataResolver {
  constructor(private readonly roleModelDataService: RoleModelDataService) {}

  @Query(() => [RoleModelData], { name: 'roleModelDatas' })
  // @UseGuards(JwtAuthGuard)
  findAll() {
    return this.roleModelDataService.findAll();
  }

  @Query(() => RoleModelData, { name: 'roleModelData' })
  findOne(@Args('id', { type: () => Int }) id: number) {
    return this.roleModelDataService.findOne(id);
  }

  @Mutation(() => RoleModelData)
  removeRoleModelDatum(@Args('id', { type: () => Int }) id: number) {
    return this.roleModelDataService.remove(id);
  }

  @ResolveField(() => [KeyValueList])
  bagItems(@Parent() role: RoleModelData) {
    const list = Array.from(role.bagItems.entries());
    return list.map(([key, value]) => ({
      key,
      value,
    }));
  }

  @ResolveField(() => [KeyValueList])
  heroFormations(@Parent() role: RoleModelData) {
    const list = Array.from(role.heroFormations.entries());
    return list.map(([key, value]) => ({
      key,
      value,
    }));
  }

  @ResolveField(() => [KeyValueList])
  levelDataUids(@Parent() role: RoleModelData) {
    const list = Array.from(role.levelDataUids.entries());
    return list.map(([key, value]) => ({
      key,
      value,
    }));
  }
}
